<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__UI__/css/bs3/dpl.css" rel="stylesheet">
<link href="__UI__/css/bs3/bui.css" rel="stylesheet">
<link href="__UI__/css/page.css" rel="stylesheet" type="text/css" />
<style type="text/css">

.title {
	text-align:center;
	margin-bottom:20px;
}

</style>
</head>
<body> 
<div class="container">
	<h2 class="title">{$scripts.scriptsname} —— 场景</h2>
	<div class="search-grid-container">
		<div id="grid"></div>
	</div>
</div>
<script type="text/javascript" src="__UI__/js/jquery-1.8.1.min.js"></script>
<script type="text/javascript" src="__UI__/js/bui.js"></script>
<script type="text/javascript" src="__UI__/js/config.js"></script>
<script type="text/javascript">
	top.topManager.closePage('scene_add');
	top.topManager.closePage('scene_edit');
	BUI.use('common/page');
	BUI.use(['common/search','bui/overlay'],function (Search,Overlay){
		var columns = [
			{title:'场景名称',dataIndex:'scenename',width:100},
			{title:'场景说明',dataIndex:'brief',width:300},
			{title:'操作',dataIndex:'',width:100,renderer:function(value,obj){
				var sceneStr = Search.createLink({
					id:'scene_edit',
					title:'编辑场景',
					text:'编辑&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
					href:'{:U("Home/Scene/edit/id/' + obj.id + '")}',
					isClose:true,
				}),
				delStr = '<span class="grid-command btn-del" title="场景删除">删除</span>&nbsp;&nbsp;';
				Search.createLink;
				return sceneStr + delStr;
			}},
			{title:'移动',dataIndex:'cj',width:100},
		],
		store = Search.createStore('{:U("Scene/index",array("id"=>I("get.id"),"sid"=>I("get.sid")))}',{
			proxy:{
				save:{removeUrl:'{:U("Scene/index",array("id"=>I("get.id"),"sid"=>I("get.sid")))}'}
			},
			autoSync:true,
			pageSize:10,
			
		}),
		gridCfg = Search.createGridCfg(columns,{
			forceFit:true,
			tbar:{
				items:[
					{text : '<i class="icon-refresh"></i>刷新页面',btnCls : 'button button-small',handler:function(){
						window.location.reload();
					}},
					{text : '<i class="icon-plus"></i>场景新建',btnCls : 'button button-small',handler:function(){
						top.topManager.openPage({
							id:'scene_add',
							title:'场景新建',
							href:'{:U("Scene/add",array("id"=>I("get.id"),"sid"=>I("get.sid")))}',
							isClose:true,
						});
					}},
					{text:'<i class="icon-remove"></i>批量删除',btnCls:'button button-small',handler:delFunction},
				]
			},
			plugins:[BUI.Grid.Plugins.CheckSelection,BUI.Grid.Plugins.RowNumber] 
		});
		var  search = new Search({
			store:store,
			gridCfg:gridCfg,
		}),
		grid = search.get('grid');
		function delFunction(){
			var selections = grid.getSelection();
			delItems(selections);
		}
		function delItems(items){
			var ids = [];
			BUI.each(items,function(item){
				ids.push(item.id);
			});
			if(ids.length){
				BUI.Message.Confirm('确认要删除选中的记录么？',function(){
					$.ajax({
						url:'{:U("Scene/del")}',
						dataType:'json',
						data:{ids : ids},
						success:function(data){
							if(data.status == 'y'){
								search.load();
							}else{
								BUI.Message.Alert('删除失败！');
							}
						}
					});
				},'question');
			}
		}
		grid.on('cellclick',function(ev){
			var sender = $(ev.domTarget);
			if(sender.hasClass('btn-del')){
				var record = ev.record;
				delItems([record]);
			}
		});
		
		function upFunction(){
			var selections = grid.getSelection();
			upItems(selections);
		}
		function upItems(items,k){
			var ids = [];
			BUI.each(items,function(item){
				ids.push(item.id);
			});
			if(ids.length){
				$.ajax({
					url:'{:U("Scene/remove")}',
					dataType:'json',
					data:{k:'up', ids:ids},
					success:function(data){
						if(data.status == 'y'){
							search.load();
						}else{
							BUI.Message.Alert('移动失败！');
						}
					}
				});
			}
		}
		
		grid.on('cellclick',function(ev){
			var sender = $(ev.domTarget);
			if(sender.hasClass('btn-up')){
				var record = ev.record;
				upItems([record]);
			}
		});
		
		function downFunction(){
			var selections = grid.getSelection();
			downItems(selections);
		}
		function downItems(items,k){
			var ids = [];
			BUI.each(items,function(item){
				ids.push(item.id);
			});
			if(ids.length){
				$.ajax({
					url:'{:U("Scene/remove")}',
					dataType:'json',
					data:{k:'down', ids:ids},
					success:function(data){
						if(data.status == 'y'){
							search.load();
						}else{
							BUI.Message.Alert('移动失败！');
							//BUI.Message.Alert(data.info);
						}
					}
				});
			}
		}
		
		grid.on('cellclick',function(ev){
			var sender = $(ev.domTarget);
			if(sender.hasClass('btn-down')){
				var record = ev.record;
				downItems([record]);
			}
		});
	});

</script>
</body>
</html>
